import initServerInstance from '../server/initServerInstance';

/**
 * 套餐/余额 aviliableMaxNode 类型改为 max
 */
if (require.main === module) {
	(async () => {
		const server = await initServerInstance({
			loggerConfig: {
				name: 'upgrade',
				alwaysCreate: true,
			},
		});
		const {
			app: { model },
		} = server;
		const { Balance, Plan } = model;

		for await (const plan of Plan.find()) {
			plan.limit.aviliableMaxNode.limitType = 'max';
			await plan.save();
		}

		for await (const balance of Balance.find()) {
			balance.balance.aviliableMaxNode.limitType = 'max';
			balance.balance.aviliableMaxNode.charges.forEach(c => {
				c.limitType = 'max';
			});
			await balance.save();
		}

		process.exit();
	})();
}
